const {TableConfig} = require("../index");
const {Postgresql, DynamicQuery, PageResponse, switchSqlLog} = require('../index');
switchSqlLog(true)


const log = (value) => {
    console.log(JSON.stringify(value, null, 2))
};

(async () => {

    const postgresql = new Postgresql({
        host: '192.168.1.97',
        port: 5432,
        user: 'admin',
        password: 'Jimmy007',
        database: 'nestjs-test'
    });

    await postgresql.connect();
    const userConfig = new TableConfig("user_info", [
        "id",
        "name",
        "age",
        "department_id"
    ]);
    userConfig.parents.push({
        parentObject: "department",
        parentTable: "department_info",
        parentIdName: "id",
        parentId: "department_id"
    })
    const dynamicQuery = new DynamicQuery(userConfig, postgresql);
    const saveResult = await dynamicQuery.save({name: 'zh', age: 13, department_id: 1});
    const list = await dynamicQuery.navigationFindAll({});
    log(list)
    await dynamicQuery.remove([saveResult.id]);
})()